package com.gistmap.cloudservicegateway.config;

import com.gistmap.cloudservicegateway.filter.SimpleFilter;
import org.springframework.cloud.netflix.zuul.filters.discovery.ServiceRouteMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zhangran
 * @date 2018/6/6
 */
@Configuration
public class FilterConfig {

    private final static String CONSUL = "consul";
    @Bean
    public SimpleFilter signatureFilter(){
        return new SimpleFilter();
    }

    @Bean
    public ServiceRouteMapper mapper() {
        return serviceId -> {
            System.out.println(serviceId);
            if (serviceId.equals(CONSUL)){
                return "consul";
            }
            String[] serviceStr = serviceId.split("-");
            return serviceStr[2];
        };
    }
}
